package com.qyhl.module_practice.service;

import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.module_practice.R;
import com.qyhl.module_practice.R2;
import com.qyhl.module_practice.activity.PracticeActFragment;
import com.qyhl.module_practice.team.list.PracticeTeamListFragment;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionLogUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterPathConstant.PRACTICE_SERVICE)
public class PracticeServiceActivity extends BaseActivity {
    @BindView(R2.id.title)
    TextView title;
    @BindView(R2.id.tabLayout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;

    @Override
    protected int getContentView() {
        return R.layout.practice_activity_service;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {

    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        String titleName = getIntent().getStringExtra("title");
        String instId = getIntent().getStringExtra("instId");
        String volId = getIntent().getStringExtra("volId");
        int volStatus = getIntent().getIntExtra("volStatus", 0);

        title.setText(StringUtils.isNotEmpty(titleName) ? titleName : "志愿服务");
        List<String> nameList = new ArrayList<>();
        List<Fragment> fragments = new ArrayList<>();
        nameList.add("志愿团体");
        nameList.add("志愿活动");
        fragments.add(PracticeTeamListFragment.newInstance(instId, volId, volStatus, "", false, false));
        fragments.add(PracticeActFragment.newInstance(instId, 0, instId, "0,3"));
        viewPager.setAdapter(new Adapter(getSupportFragmentManager(), fragments, nameList));
        tabLayout.setViewPager(viewPager);
    }

    @Override
    protected void setListener() {

    }


    @OnClick(R2.id.back_btn)
    public void onViewClicked() {
        finish();
    }

    class Adapter extends FragmentPagerAdapter {
        private List<Fragment> fragmentList;
        private List<String> names;

        Adapter(FragmentManager fm, List<Fragment> fragmentList, List<String> names) {
            super(fm);
            this.fragmentList = fragmentList;
            this.names = names;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        ActionLogUtils.getInstance().onResume(this, ActionConstant.PRACTICE_SERVICE);
    }

    @Override
    protected void onPause() {
        super.onPause();
        ActionLogUtils.getInstance().onPause(this, ActionConstant.PRACTICE_SERVICE);
    }
}
